package com.micro.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 酒店服务客户端
 */
@FeignClient(name = "hotel-service", fallback = HotelServiceClientFallback.class)
public interface HotelServiceClient {

    /**
     * 处理酒店库存
     */
    @PostMapping("/api/hotels/inventory/process")
    boolean processInventory(
        @RequestParam("hotelId") Long hotelId,
        @RequestParam("roomType") String roomType,
        @RequestParam("checkInDate") LocalDate checkInDate,
        @RequestParam("checkOutDate") LocalDate checkOutDate,
        @RequestParam("roomCount") Integer roomCount
    );

    /**
     * 获取酒店信息
     */
    @GetMapping("/api/hotels/id/{hotelId}")
    HotelDTO getHotelById(@PathVariable("hotelId") Long hotelId);

    /**
     * 酒店DTO
     */
    class HotelDTO {
        private Long hotelId;
        private String hotelName;
        private String hotelType;
        private String address;
        private String phone;
        private BigDecimal price;
        private Integer availableRooms;

        // Getter和Setter方法
        public Long getHotelId() {
            return hotelId;
        }

        public void setHotelId(Long hotelId) {
            this.hotelId = hotelId;
        }

        public String getHotelName() {
            return hotelName;
        }

        public void setHotelName(String hotelName) {
            this.hotelName = hotelName;
        }

        public String getHotelType() {
            return hotelType;
        }

        public void setHotelType(String hotelType) {
            this.hotelType = hotelType;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public BigDecimal getPrice() {
            return price;
        }

        public void setPrice(BigDecimal price) {
            this.price = price;
        }

        public Integer getAvailableRooms() {
            return availableRooms;
        }

        public void setAvailableRooms(Integer availableRooms) {
            this.availableRooms = availableRooms;
        }
    }
}

/**
 * 酒店服务客户端降级处理
 */
class HotelServiceClientFallback implements HotelServiceClient {

    @Override
    public boolean processInventory(Long hotelId, String roomType, LocalDate checkInDate, LocalDate checkOutDate, Integer roomCount) {
        return false;
    }

    @Override
    public HotelDTO getHotelById(Long hotelId) {
        return null;
    }
}
